*******************************************
** May 2022
* FOLLOW FROM WIP_main_jan2022_fourcand
*EDIT: FIX THE effective number of observations
*******************************************


*******************************************
*REPLICATION DO FILE FOR 
*Does the number of candidates increase turnout? 
*Causal evidence from two-round elections

* Date: June 2022
* Note: Install package mccrary test and then un-comment lines
*******************************************



**************************************************************************************
*SECTION A. SUMMARY STATISTICS AND SOME CLEANING/VARIABLES 
*SECTION B. RDD GRAPHS AND TESTS OF INTERNAL VALIDITY 
*SECTION C. MAIN RESULTS
*SECTION D. (MAIN )HETEROGENEOUS EFFECTS
*SECTION E. APPENDIX WITH MANY ADDITIONAL ANALYSIS
**************************************************************************************

**************************************************************************************
*LOCATIONS

global dropbox "/Users/ivandic/Dropbox/RDD france/"
global intermediate "${dropbox}data/"

global replicationinput "/Users/ivandic/Dropbox/RDD france/code/replication polbeh/"

*global replication "/Users/ivandic/Dropbox/RDD france/Submission Political Behavior/cond acceptance/"

global replication "/Users/ivandic/Dropbox/RDD france/code/replication polbeh/output/"



*******************************************
*LOAD DATA
use "${intermediate}masterdata.dta", replace
*******************************************



forvalues i=1/3 {
label var party_can`i' "Party, `i'. ranked"
label var voteshare_t1_can`i' "Vote Share 1st round, `i'. ranked"
label var voteshare_t2_can`i' "Vote Share 2nd round, `i'. ranked"
label var threshold_party_can`i' "Qual Threshold, `i'. ranked"
label var dummy_threshold_can`i' "Fake threshold, `i'. ranked"
label var ran_t2_can`i' "Ran in 2nd round, `i'. ranked"
label var running_can`i' "Running variable, `i'. ranked"
label var running_false_can`i' "Fake Running variable, `i'. ranked"
label var ideology_can`i' "Ideology, `i'. ranked"
}

drop votants_t1 turnout_elect_t2 blancsnull_elect_t2 diffvote_can3 diffvote_can2 blancsnull_diff turnout_diff cvotes_diff T1_turnout_t2 T1_blancsnull_t2 T1_cvotes_t2 T1_turnout_t1 T1_blancsnull_t1 T1_cvotes_t1


save "${replicationinput}replicationdata.dta", replace


*******************************************
*LOAD DATA
use "${replicationinput}replicationdata.dta", clear




***************************************************************************************
* SECTION A. SUMMARY STATISTICS AND SOME CLEANING/VARIABLES 
****************************************************************************************


*******************************************
*Summary statistics
tab year
summ turnout_t2 cvotes_t2 blancsnull_t2
tab threecand
tab fourmorecand

*******************************************
*Drop if there are four or more candidates in second round 
*******************************************
count 
drop if fourmorecand==1

*******************************************

count
*table 2. panel 1 and 2
eststo two: estpost summarize turnout_t1 turnout_t2 blancsnull_t1 blancsnull_t2 cvotes_t1 cvotes_t2     parties_t1    parties_t2 inscrits_t1 if nosecond==0, det
*Export the summary stats
esttab two, replace cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))")  page label
esttab  two using "${replication}summary1_v3.tex", replace cells(" mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))")  page label

eststo clear

eststo three: estpost summarize  turnout_t1 turnout_t2 blancsnull_t1 blancsnull_t2 cvotes_t1 cvotes_t2 if parties_t2==2, det
eststo four: estpost summarize turnout_t1 turnout_t2 blancsnull_t1 blancsnull_t2 cvotes_t1 cvotes_t2  if parties_t2==3, det
*Export the summary stats

esttab three, replace cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2))  max(fmt(2))") page  label
esttab  four, cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2))  max(fmt(2))")  page label append

esttab three   using "${replication}summary_23cand_v3.tex", replace cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2))  max(fmt(2))") page  label
esttab  four  using "${replication}summary_23cand_v3.tex", cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2))  max(fmt(2))")  page label append

eststo clear


eststo five: estpost summarize third_winning 

***************************************************************************************
*Summary stats on the winning candidate
***************************************************************************************

gen win_firstrank=(id_winning==1)
label var win_firstrank "1st Ranked in 1st Round Wins"

gen win_secondrank=(id_winning==2)
label var win_secondrank "2nd Ranked in 1st Round Wins"

gen win_thirdrank=(id_winning==3)
label var win_thirdrank "3rd Ranked in 1st Round Wins"

eststo one: estpost summarize win_firstrank win_secondrank win_thirdrank
eststo two: estpost summarize win_firstrank win_secondrank win_thirdrank if parties_t2==2, det
eststo three: estpost summarize win_firstrank win_secondrank win_thirdrank if parties_t2==3, det
esttab one two three   using "${replication}summary_win.tex", replace cells("mean(fmt(2)) sd(fmt(2)) ") page  label
esttab one two three, cells("mean(fmt(2)) sd(fmt(2)) ") 
eststo clear


***************************************************************************************
*Descriptive evidence

* How often are elections terminated after first round?
tab elected_t1
tab elected_t1 if election==("national")
tab elected_t1 if election==("cantonal")


* How often do candidates drop out if the third candidate qualifies?
cap drop qualified_can3
g qualified_can3=(running_can3>=0)

tab parties_t2 if qualified_can3==1

tab qualified_can3 ran_t2_can3, row
tab ran_t2_can1 if qualified_can3==1
tab ran_t2_can2 if qualified_can3==1
tab ran_t2_can3 if qualified_can3==1
 

* How often does the first ranked win?
tab id_winning
tab id_winning if parties_t2>2 
tab id_winning if threecand==1
tab id_winning if qualified_can3==1
* Results differ because of the drop-outs, i.e. qualified_can3==1 is not equal to parties_t2>2

tab  win_firstrank if parties_t2>2 
tab win_thirdrank if parties_t2>2 


***************************************************************************************
* SECTION B. RDD GRAPHS AND TESTS OF INTERNAL VALIDITY 
****************************************************************************************


* PLOT MCCRARY TEST
*Important: Mccrary test put .ado in folder
*DCdensity running_can3 , breakpoint(0) generate(Xj Yj r0 fhat se_fhat)  
*cap drop Yj Xj r0 fhat se_fhat
*graph save "${replication}mccrary_v3.png", replace
*Discontinuity estimate in  (Log difference in height): -.029326981 (SE: 0.056673266)


* HISTOGRAM
hist running_can3,   xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)) 
graph save "${replication}hist_running_v3.png", replace

*RDD plot First stage
rdplot threecand running_can3 , p(1) nbins(25) graph_options(title(, size(medium)) graphregion(color(white))  legend(off) ///
ytitle(Three candidates running in the second round, size(medsmall)) ///
xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}firststage_v5.png", replace

rdrobust threecand running_can3, fuzzy(threecand) kernel(triangular)  p(1)


**********************************************************
** CONTINUINITY OF COVARIATES 
**********************************************************

eststo clear

*** Constituency and Election Characteristics  
	*Size (registered in first round)
rdplot inscrits_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Registered Voters, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_registered_v3.png", replace
eststo: rdrobust inscrits_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Paris
rdplot paris running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(District in Paris, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_paris_v3.png", replace
eststo: rdrobust paris running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Timing of Election
rdplot before2000 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Election Before 2000, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_before2000_v3.png", replace	
eststo: rdrobust before2000 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Number of candidates in first round
rdplot parties_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Number of Parties (1st Round), size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_parties_v3.png", replace	
eststo: rdrobust parties_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Turnout in 1st Round
rdplot turnout_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Turnout in 1st Round, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_turnout_t1_v3.png", replace	
eststo: rdrobust turnout_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Blanc and Null Votes in 1st Round
rdplot blancsnull_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Blanc and Null Votes in 1st Round, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_blancsnull_t1_v3.png", replace			
eststo: rdrobust blancsnull_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Export
esttab using "${replication}table_discontinuity_v4.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))
	
	
*** Candidates' characteristics:
eststo clear

*absolute votes of first candidate
rdplot voteshare_t1_can1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) ytitle(Total Votes in 1st Round Strongest Candidate, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_voteshare1_v3.png", replace
eststo: rdrobust voteshare_t1_can1   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*relative vote share of 1st candidate
rdplot relshare_t1_can1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) ytitle(Vote Share in 1st Round Strongest Candidate, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_relshare1_v3.png", replace
eststo: rdrobust relshare_t1_can1   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*relative vote share of 2nd candidate
rdplot relshare_t1_can2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) ytitle(Vote Share in 1st Round Second Candidate, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_relshare2_v3.png", replace
eststo: rdrobust relshare_t1_can2   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*magin in the first round
rdplot margin_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Margin of Victory in 1st Round, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_margin_v3.png", replace
eststo: rdrobust margin_t1   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*third candidate mainstream
rdplot third_mainstream running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Mainstream Third Candidate, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_third_mainstream_v3.png", replace
eststo: rdrobust third_mainstream   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*third candidate major
rdplot third_major running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Third Candidate from Major Party, size(medsmall)) xtitle(Vote Share of 3rd Candidate in the 1st Round Compared to Threshold, size(medsmall)))
graph export "${replication}robust_third_major_v3.png", replace
eststo: rdrobust third_major   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*internal check
* eststo: rdrobust relshare_t1_high   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*Export
esttab using "${replication}table_discontinuity2_v4.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))

	
*** District and Election Characteristics: 
	
eststo clear

	*Size (registered in first round)
eststo: rdrobust inscrits_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Number of candidates in first round
eststo: rdrobust parties_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*Turnout in 1st Round
eststo: rdrobust turnout_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*Export table district/election
esttab using "${replication}newtable_discontinuity_de_v2.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


* Graphs
rdplot inscrits_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Registered voters in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_de1.png", replace

rdplot parties_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Number of candidates in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_de2.png", replace

rdplot turnout_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Turnout in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_de3.png", replace


*** Candidates' characteristics:
eststo clear

	*votes of first candidate
eststo: rdrobust voteshare_t1_can1   running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*votes of second candidate
eststo: rdrobust voteshare_t1_can2 running_can3, fuzzy(threecand) kernel(triangular) p(1)

eststo: rdrobust margin_t1 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

	*magin in the first round
eststo: rdrobust margin_t2 running_can3, fuzzy(threecand) kernel(triangular)  p(1)

*Export table candidate
esttab using "${replication}newtable_discontinuity_c_v2.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear

* Graphs
rdplot voteshare_t1_can1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Number of votes for 1st candidate in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_c1.png", replace

rdplot voteshare_t1_can2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Number of votes for 2nd candidate in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_c2.png", replace

rdplot margin_t2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Margin of victory in 2nd round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_c3.png", replace


rdplot margin_t1 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Margin of victory in 1st round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}margin_t1.png", replace


***************************************************************************************
* SECTION C. MAIN RESULTS
****************************************************************************************


*Main Result figure
rdplot blancsnull_t2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(Blank and null votes in 2nd round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}robust_nullblank2_v3.png", replace 
rdplot cvotes_t2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))   ytitle(Valid votes in 2nd round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}robust_cvotes2_v3.png", replace
rdplot turnout_t2 running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))   ytitle(Turnout in 2nd round, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}robust_turnout2_v3.png", replace



eststo clear

*Table 1
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(1)
}
*Export
esttab using "${replication}table1_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear



*Table 1 (Appendix)
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(ran_t2_can3) kernel(triangular)  p(1)
}
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(1)
}

* NOTE: effect on turnout_t2 is less significant than in ran_t2_can3 treatment 

*Export
esttab using "${replication}appendix_table1_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


eststo clear

*Table APPENDIX- DV=LAGGED
foreach var in Lagblancsnull_t2 Lagturnout_t2 Lagcvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(1)
}
*Export
esttab using "${replication}table1_Lag_v1.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))

eststo clear


************************************************************************
*ROBUSTNESS FAKE THRESHOLD 
************************************************************************

rdplot threecand running_false_can3 , p(1) nbins(25) graph_options( legend(off) graphregion(color(white))  ytitle(Three candidates in second round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}rdplot_inverted_v3.png", replace

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {

eststo: rdrobust `var' running_false_can3, fuzzy(threecand) kernel(triangular)  p(1)
}

*Export
esttab using "${replication}table_inverted_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))

eststo clear


************************************************************************
*OUTCOME: MARGINS 
************************************************************************

foreach var in margin_t1 margin_t2  {

eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(1)
}

*Export
esttab using "${replication}table_marginvictory_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


** Mechanism: Split on Competition:

foreach var in blancsnull_t2  cvotes_t2 turnout_t2 {
eststo: rdrobust `var' running_can3 if relshare_t1_low==1 , fuzzy(threecand) kernel(triangular)  p(1)
}
foreach var in blancsnull_t2  cvotes_t2 turnout_t2 {
eststo: rdrobust `var' running_can3 if relshare_t1_high==1 , fuzzy(threecand) kernel(triangular)  p(1)
}

* Export 

esttab using "${replication}table_competition_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear	
	

foreach var in voteshare_t2_can12 relshare_t2_can12 {
eststo: rdrobust `var' running_can3 , fuzzy(threecand) kernel(triangular)  p(1)
}


***************************************************************************************
* SECTION D. HETEROGENEOUS EFFECTS
****************************************************************************************


/*
 -	Cantonal vs	National
-	Before/After 2002 (this is when the Front National candidate was qualified for the second round of the president election)
-	When the two first candidates are mainstream AND third candidate is mainstream as well
-	When the two first candidates are mainstream AND third candidate is extreme (left or right)
-	When the two first candidates are mainstream AND third candidate is extreme-right
-	When the two first candidates are from the same bloc (left or right) AND third candidate is from the other bloc 
*/

*GRAPHS (Not in paper)
rdplot turnout_t2 running_can3 if election=="cantonal", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(Cantonal, ///
size(medium)) ytitle(Turnout in 2nd round, size(medsmall)) ///
xtitle(Vote Share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))

rdplot blancsnull_t2 running_can3 if election=="cantonal", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(Cantonal, ///
size(medium)) ytitle(Blank and null votes in 2nd round, size(medsmall)) ///
xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))

rdplot cvotes_t2 running_can3 if election=="cantonal", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(Cantonal, ///
size(medium)) ytitle(Valid turnout in 2nd round, size(medsmall)) ///
xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))

rdplot turnout_t2 running_can3 if election=="national", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(National, ///
size(medium)) ytitle(Turnout in 2nd round, size(medsmall)) ///
xtitle(Vote Share of 3rd Candidate in the 1st round compared to threshold, size(medsmall)))

rdplot blancsnull_t2 running_can3 if election=="national", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(National, ///
size(medium)) ytitle(Blank and null votes in 2nd round, size(medsmall)) ///
xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))

rdplot cvotes_t2 running_can3 if election=="national", p(1) nbins(25) ///
graph_options(legend(off) graphregion(color(white)) title(Cantonal, ///
size(medium)) ytitle(Valid turnout in 2nd round, size(medsmall)) ///
xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))


eststo clear

* When the election is cantonal
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if election=="cantonal", fuzzy(threecand) kernel(triangular) p(1)
}

* When the election is national
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if election=="national", fuzzy(threecand) kernel(triangular) p(1)
}

* Export national/cantonal

esttab using "${replication}newtable_heterogeneous_nat_v2.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' )) mgroups("Cantonal" "National", pattern(1 0 0 1 0 0)) 

eststo clear


* When the election was before 2002
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if year<2002, fuzzy(threecand) kernel(triangular)  p(1)
}

* When the election was after 2002
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if year>=2002, fuzzy(threecand) kernel(triangular)  p(1)
}

*Export before/after 2002
esttab using "${replication}newtable_heterogeneous_2002.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' )) mgroups("Before 2002" "After 2002", pattern(1 0 0 1 0 0)) 


eststo clear

***************************************************************************************
*IDEOLOGY
***************************************************************************************

*When the two first candidates are mainstream AND third candidate is mainstream as well
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if mainstream==1, fuzzy(threecand) kernel(triangular)  p(1)
}

*When the two first candidates are mainstream AND third candidate is extreme-right
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if extreme_right==1, fuzzy(threecand) kernel(triangular)  p(1)
}


*Export
esttab using "${replication}table_heterogeneous_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


rdplot blancsnull_t2 running_can3 if extreme_right==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) title(Extreme Right, size(medium)) ytitle(Blank and null votes in 2nd round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_nullblank2_v3_FN.png", replace 

rdplot blancsnull_t2 running_can3 if mainstream==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) title(Mainstream, size(medium)) ytitle(Blank and null votes in 2nd round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_nullblank2_v3_MS.png", replace 

rdplot cvotes_t2 running_can3 if extreme_right==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  title(Extreme Right, size(medium)) ytitle(Valid turnout in 2nd tound, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_cvotes2_v3_FN.png", replace

rdplot cvotes_t2 running_can3 if mainstream==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  title(Mainstream, size(medium)) ytitle(Valid turnout in 2nd round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_cvotes2_v3_MS.png", replace

rdplot turnout_t2 running_can3 if extreme_right==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white)) title(Extreme Right, size(medium)) ytitle(Turnout in 2nd round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_turnout2_v3_FN.png", replace
rdplot turnout_t2 running_can3 if mainstream==1, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  title(Mainstream, size(medium)) ytitle(Turnout in 2nd round, size(medsmall)) xtitle(Vote share of 3rd candidate in the 1st round compared to threshold, size(medsmall)))
graph export "${replication}robust_turnout2_v3_MS.png", replace


*When the two first candidates are mainstream AND third candidate is extreme-right
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if extreme_right_second==1, fuzzy(threecand) kernel(triangular)  p(1)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if same_ideology==1, fuzzy(threecand) kernel(triangular)  p(1)
}


*Export
esttab using "${replication}table_heterogeneous_additions_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


*When the two first candidates are from the same bloc (left or right) AND third candidate is from the other bloc 

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if different_bloc==1, fuzzy(threecand) kernel(triangular)  p(1)
}


*extreme right second in the election
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if extreme_right_second==1, fuzzy(threecand) kernel(triangular)  p(1)
}


*Export
esttab using "${replication}table_blocs_v2.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear



***************************************************************************************
* SECTION E. APPENDIX
****************************************************************************************

eststo clear


*Table1  Appendix - Polynomials
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(2)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(3)
}


*Export
esttab using "${replication}appendix_T1_polynomial_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear



*Table2 Appendix - Bandwidth


foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular) bwselect(cerrd) p(1)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  h(0.05) p(1)
}

*Export Bandwidth
esttab using "${replication}appendix_Bandwidth_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))

	
eststo clear


*Table3 Appendix - Kernel
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(uniform)  p(1)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(epanechnikov)  p(1)
}


*Export
esttab using "${replication}appendix_kernel_v3.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear



*Table7 Fixed effects all
*stronger specification
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
reghdfe `var' threecand , absorb(year id_unique ) vce(robust)
estimates save "${replication}fe_`var'_v3", replace
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
reghdfe `var' threecand if running_can3>-0.03 & running_can3<0.03 , absorb(year id_unique ) vce(robust)
estimates save "${replication}fe2_`var'_v3", replace

}

*Export
estimates use "${replication}/fe_blancsnull_t2_v3"
	outreg2 using "${replication}/temp.tex", ///
		replace  nocons label tex(frag)  dec(2)  nonotes  addtext(Canton FE, YES, Election FE, YES) ///
		addnote(`"\begin{flushleft}\tiny{${note1}}\end{flushleft}"', `"\begin{flushleft}\tiny{${note2}}\end{flushleft}"', `"\begin{flushleft}\tiny{${note3}}\end{flushleft}"') 
estimates use "${replication}/fe_turnout_t2_v3"
		 outreg2 using "${replication}/temp.tex", ///
			append nocons label tex(frag)  dec(2)  nonotes addtext(Canton FE, YES, Election FE, YES)
estimates use "${replication}/fe_cvotes_t2_v3"
		 outreg2 using "${replication}/temp.tex", ///
			append nocons label tex(frag)  dec(2)  nonotes addtext(Canton FE, YES, Election FE, YES)
estimates use "${replication}/fe2_blancsnull_t2_v3"
		 outreg2 using "${replication}/temp.tex", ///
			append nocons label tex(frag)  dec(2)  nonotes addtext(Canton FE, YES, Election FE, YES)
estimates use "${replication}/fe2_turnout_t2_v3"
		 outreg2 using "${replication}/temp.tex", ///
			append nocons label tex(frag)  dec(2)  nonotes addtext(Canton FE, YES, Election FE, YES)
estimates use "${replication}/fe2_cvotes_t2_v3"
		 outreg2  using "${replication}/temp.tex", ///
			append  nocons label tex(frag)  dec(2) nonotes  addtext(Canton FE, YES, Election FE, YES) ///
			title("")
copy "${replication}/temp.tex" "${replication}/appendix_FE_v3.tex",replace

eststo clear


*exclude non-compliers
gen noncompliers=(running_can3>=0 & threecand==0)


**Table5 Appendix - Sharp RDD + Sharp RDD, exclude non-compliers

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3,  kernel(triangular)  p(1)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if noncompliers==0,  kernel(triangular)  p(1)
}


*Export
esttab using "${replication}appendix_sharp_rdd.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear

****************************************************************
* ADDITIONAL ROBUSTNESS FOR APPENDIX
*requires reloading the dataset
****************************************************************


use "${replicationinput}replicationdata.dta", clear


count 
drop if fourmorecand==1
count



********************************************
*TURNOUT
********************************************

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.01) p(1)
estimates store turnout_t2_1

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.02) p(1)
estimates store turnout_t2_2

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.03) p(1)
estimates store turnout_t2_3

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.04) p(1)
estimates store turnout_t2_4

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.05) p(1)
estimates store turnout_t2_5

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.06) p(1)
estimates store turnout_t2_6

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.07) p(1)
estimates store turnout_t2_7

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.08) p(1)
estimates store turnout_t2_8

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.09) p(1)
estimates store turnout_t2_9

eststo: rdrobust turnout_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.1) p(1)
estimates store turnout_t2_10

coefplot turnout_t2_1 turnout_t2_2 turnout_t2_3 turnout_t2_4 turnout_t2_5 turnout_t2_6 turnout_t2_7 turnout_t2_8 turnout_t2_9 turnout_t2_10, vertical yline(0) legend(off) replace mcolor(black)ciopts(lcolor(black) recast(rcap)) gen(_c) 

keep _c*
cap drop bw
gen bw = . //identify to which bandwidth size the estimates belong
local bw_sizes 1 2 3 4 5 6 7 8 9 10 
forvalues i = 1/10{
local bw_value: word `i' of `bw_sizes'
replace bw = `bw_value' if [_n] == `i'
}

// Plot point estimates and CI against bandwidth size
scatter _cb bw, mc(black) || rcap _cul1 _cll1 bw, lc(black) ||, yline(0, lp(dash)) xtitle("RD bandwidth", margin(small)) ytitle("RD coefficiant (95% CI)", margin(small)) legend(off) graphregion(color(white)) xlabel(#10)
graph export "${replication}/turnout_t2_BWsensitivity.png", replace 
 
********************************************
*blancsnull_t2
********************************************

use "${replicationinput}replicationdata.dta", clear
count 
drop if fourmorecand==1
count

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.01) p(1)
estimates store blancsnull_t2_1

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.02) p(1)
estimates store blancsnull_t2_2

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.03) p(1)
estimates store blancsnull_t2_3

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.04) p(1)
estimates store blancsnull_t2_4

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.05) p(1)
estimates store blancsnull_t2_5

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.06) p(1)
estimates store blancsnull_t2_6

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.07) p(1)
estimates store blancsnull_t2_7

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.08) p(1)
estimates store blancsnull_t2_8

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.09) p(1)
estimates store blancsnull_t2_9

eststo: rdrobust blancsnull_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.1) p(1)
estimates store blancsnull_t2_10

coefplot blancsnull_t2_1 blancsnull_t2_2 blancsnull_t2_3 blancsnull_t2_4 blancsnull_t2_5 blancsnull_t2_6 blancsnull_t2_7 blancsnull_t2_8 blancsnull_t2_9 blancsnull_t2_10, vertical yline(0) legend(off) replace mcolor(black)ciopts(lcolor(black) recast(rcap)) gen(_c) 

keep _c*
cap drop bw
gen bw = . //identify to which bandwidth size the estimates belong
local bw_sizes 1 2 3 4 5 6 7 8 9 10 
forvalues i = 1/10{
local bw_value: word `i' of `bw_sizes'
replace bw = `bw_value' if [_n] == `i'
}

// Plot point estimates and CI against bandwidth size
scatter _cb bw, mc(black) || rcap _cul1 _cll1 bw, lc(black) ||, yline(0, lp(dash)) xtitle("RD bandwidth", margin(small)) ytitle("RD coefficiant (95% CI)", margin(small)) legend(off)  graphregion(color(white)) xlabel(#10) ylabel(0.01(0.01)-0.05)
graph export "${replication}/blancsnull_t2_BWsensitivity.png", replace 




********************************************
*cvotes_t2
********************************************

use "${replicationinput}replicationdata.dta", clear

count 
drop if fourmorecand==1
count


eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.01) p(1)
estimates store cvotes_t2_1

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.02) p(1)
estimates store cvotes_t2_2

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.03) p(1)
estimates store cvotes_t2_3

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.04) p(1)
estimates store cvotes_t2_4

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.05) p(1)
estimates store cvotes_t2_5

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.06) p(1)
estimates store cvotes_t2_6

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.07) p(1)
estimates store cvotes_t2_7

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.08) p(1)
estimates store cvotes_t2_8

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.09) p(1)
estimates store cvotes_t2_9

eststo: rdrobust cvotes_t2 running_can3, fuzzy(threecand) kernel(triangular)  h(0.1) p(1)
estimates store cvotes_t2_10

coefplot cvotes_t2_1 cvotes_t2_2 cvotes_t2_3 cvotes_t2_4 cvotes_t2_5 cvotes_t2_6 cvotes_t2_7 cvotes_t2_8 cvotes_t2_9 cvotes_t2_10, vertical yline(0) legend(off) replace mcolor(black)ciopts(lcolor(black) recast(rcap)) gen(_c) 

keep _c*
cap drop bw
gen bw = . //identify to which bandwidth size the estimates belong
local bw_sizes 1 2 3 4 5 6 7 8 9 10 
forvalues i = 1/10{
local bw_value: word `i' of `bw_sizes'
replace bw = `bw_value' if [_n] == `i'
}

// Plot point estimates and CI against bandwidth size
scatter _cb bw, mc(black) || rcap _cul1 _cll1 bw, lc(black) ||, yline(0, lp(dash)) xtitle("RD bandwidth", margin(small)) ytitle("RD coefficiant (95% CI)", margin(small)) legend(off) graphregion(color(white)) xlabel(#10) ylabel(-0.01(0.02)0.12)
graph export "${replication}/cvotes_t2_BWsensitivity.png", replace 



****************************************************************************************
* ADDITIONAL COVARIATES FOR ROBUSTNESS OF DESIGN
****************************************************************************************


use "${replicationinput}replicationdata.dta", clear

keep if election=="national"
rename id_canton id_conscription

count 
merge m:1 departement id_conscription using "${replicationinput}clean_circonscriptions.dta"

*93% matched
keep if _merge==3

*******************************************
count 
drop if fourmorecand==1
count
*******************************************


*Variables

gen agriculture=C13_Pop15P_cs1/P13_pop
gen workers=C13_Pop15P_cs6/P13_pop
gen upperworkers=C13_Pop15P_cs3/P13_pop
gen old=P13_pop80p/P13_pop

summ agriculture workers upperworkers old
	
*** District and Election Characteristics (new version): 

label var agriculture "% employed in agriculture"
label var workers "% employed as workers"
label var upperworkers "% employed in high-status jobs"
label var old "% of 80 years+"


eststo clear


* Graphs
rdplot agriculture running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(% employed in agriculture, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_SE1.png", replace

rdplot workers running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(% employed as workers, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_SE2.png", replace

rdplot upperworkers running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(% employed in high-status jobs, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_SE3.png", replace

rdplot old running_can3, p(1) nbins(25) graph_options(legend(off) graphregion(color(white))  ytitle(% of 80 years+, size(medsmall)) xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))
graph export "${replication}discontinuity_SE4.png", replace


*Tables
eststo: rdrobust agriculture running_can3, fuzzy(threecand) kernel(triangular)  p(1)
eststo: rdrobust workers running_can3, fuzzy(threecand) kernel(triangular)  p(1)
eststo: rdrobust upperworkers running_can3, fuzzy(threecand) kernel(triangular)  p(1)
eststo: rdrobust old running_can3, fuzzy(threecand) kernel(triangular)  p(1)


*Export table 
esttab using "${replication}newtable_socioecon_discontinuity.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


	
	

****************************************************************************************
* Additional analysis 
****************************************************************************************


use "${replicationinput}replicationdata.dta", clear

*******************************************
count 
drop if fourmorecand==1

*******************************************
tab mainstream
tab extreme_right
tab different_bloc

** PARTY IDEOLOGY
*1 is extremegauche, 2 gauche, 3 droite, 4 extremedroite

gen RLR= (ideology_can1==3| ideology_can1==4) & (ideology_can2==1 | ideology_can2==2) & (ideology_can3==3 | ideology_can3==4)
label var RLR "Right-Left-Right Candidates"

gen LRL= (ideology_can1==1| ideology_can1==2) & (ideology_can2==3 | ideology_can2==4) & (ideology_can3==1 | ideology_can3==2)
label var LRL "Left-Right-Left Candidates"

tab RLR
tab LRL


eststo clear


*LEFT-RIGHT-LEFT AND RIGHT-LEFT-RIGHT COMBINATIONATIONS
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if RLR==1, fuzzy(threecand) kernel(triangular)  p(1)
}

foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if LRL==1, fuzzy(threecand) kernel(triangular)  p(1)
}


*Export
esttab using "${replication}table_heterogeneous_RR.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


*TOGETHER 
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3 if (LRL==1 | RLR==1), fuzzy(threecand) kernel(triangular)  p(1)
}


*Export
esttab using "${replication}table_heterogeneous_RR.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


*MARGIN OF VICTORY BY SUBSAMPLES

eststo: rdrobust margin_t2 running_can3 if different_bloc==1, fuzzy(threecand) kernel(triangular)  p(1)
eststo: rdrobust margin_t2 running_can3 if mainstream==1, fuzzy(threecand) kernel(triangular)  p(1)
eststo: rdrobust margin_t2 running_can3 if extreme_right==1, fuzzy(threecand) kernel(triangular)  p(1)


*Export
esttab using "${replication}table_margin_heterogeneous_RR.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))



*********************************************
*Additional analysis: dropping errors/always takes
*********************************************

use "${replicationinput}replicationdata.dta", clear


tab threecand

count 
count if threecand==1 & running_can3<0
list year departement if threecand==1 & running_can3<0

drop if threecand==1 & running_can3<0

count 
drop if fourmorecand==1
count

rdplot threecand running_can3 , p(1) nbins(25) graph_options(title(, size(medium)) graphregion(color(white))  legend(off) ///
ytitle(Three candidates running in the second round, size(medsmall)) ///
xtitle(Score of third candidate in the first round relative to qualifying threshold, size(medsmall)))


eststo clear

*Table 
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threecand) kernel(triangular)  p(1)
}
*Export
esttab using "${replication}table_errors.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear


*********************************************
*Additional analysis: keeping four candidate elections
*********************************************

use "${replicationinput}replicationdata.dta", clear


summ turnout_t2 cvotes_t2 blancsnull_t2

tab threecand
 tab fourmorecand
 
 gen threemorecand=(threecand==1 | fourmorecand==1)
 
tab threemorecand threecand


eststo clear

*Table Three or More
foreach var in blancsnull_t2 turnout_t2 cvotes_t2 {
eststo: rdrobust `var' running_can3, fuzzy(threemorecand) kernel(triangular)  p(1)
}
*Export
esttab using "${replication}table_threeormore.tex", f legend label replace  collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
stats(tau_T_cl se_tau_T_cl ci_rb kernel bwselect h_l h_r N N_h_l N_h_r p q,  layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" ///
    "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  ///
    labels( `"First Stage Estimate"' `"First Stage SE"' `"Robust 95\% CI"' `"Kernel Type"' `"BW Type"' `"Left Bandwidth"' `"Right Bandwidth"' `"Observations"'  `"Effective Observations (Left)"'  `"Effective Observations (Right)"'  ///
    `"Order Loc. Poly. (p)"' `"Order Bias (q)"' ))


eststo clear



	
